package com.csr.csrcheck.service.impl;

import com.csr.csrcheck.mapper.Flight_checkMapper;
import com.csr.csrcheck.pojo.Flight_check;
import com.csr.csrcheck.service.IFlight_checkService;
import com.csr.csrcheck.service.ex.CompanyException;
import com.csr.csrcheck.service.ex.Flight_checkException;
import com.csr.csrcheck.util.PageResult;
import com.csr.csrcheck.util.PageUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class Flight_checkServiceImpl implements IFlight_checkService {
    @Resource
    private Flight_checkMapper flight_checkMapper;

    public List<Flight_check> getFlight_checklist() {
        List<Flight_check> list = this.flight_checkMapper.getFlight_checklist();
        if (list == null)
            throw new Flight_checkException("");
        return list;
    }

    public List<Flight_check> getFlight_checklist2() {
        List<Flight_check> list = this.flight_checkMapper.getFlight_checklist2();
        if (list == null)
            throw new Flight_checkException("");
        return list;
    }

    public List<Flight_check> getFlight_checklist3() {
        List<Flight_check> list = this.flight_checkMapper.getFlight_checklist3();
        if (list == null)
            throw new Flight_checkException("");
        return list;
    }

    public PageResult getListpage(int pageNum, int pageSize, String company_name, String product_name, String product_t_name, String check_no, String publication) {
        return PageUtils.getPageResult(pageNum, pageSize, getPageInfo(pageNum, pageSize, company_name, product_name, product_t_name, check_no, publication));
    }

    public int addFlightcheck(Flight_check flight_check) {
        int row = this.flight_checkMapper.addFlightcheck(flight_check);
        if (row != 1)
            throw new CompanyException("");
        return row;
    }

    public int updateFlightcheck(Flight_check flight_check) {
        int row = this.flight_checkMapper.updateFlightcheck(flight_check);
        if (row != 1)
            throw new CompanyException("");
        return row;
    }

    public int deleteFlightcheck(int id) {
        int row = this.flight_checkMapper.deleteFlightcheck(id);
        if (row != 1)
            throw new CompanyException("");
        return row;
    }

    public Flight_check findflightByid(int id) {
        return this.flight_checkMapper.findflightByid(id);
    }

    private PageInfo<Flight_check> getPageInfo(int pageNum, int pageSize, String company_name, String product_name, String product_t_name, String check_no, String publication) {
        PageHelper.startPage(pageNum, pageSize);
        List<Flight_check> list = this.flight_checkMapper.getListpage(company_name, product_name, product_t_name, check_no, publication);
        if (list == null)
            throw new CompanyException("");
        return new PageInfo(list);
    }
}
